%%
figure
clf
clear

d = '110322';

cvar = 'NoiseHP';
dvar = 'NoiseDB';

path{1} = '\\core2quad\Behavior\Rat Noise-Burst Detection\Results\Training\';
path{2} = '\\HRLWXP7090\Behavior2\Rat Noise-Burst Detection\Results\Training\';

fprintf('\n***\n')

k = 1;
for j = 1:length(path)
    f = dir([path{j},'*',d,'.mat']);
    
    for i = 1:length(f)
        
        load(fullfile(path{j},f(i).name));

        subplot(2,4,k)
        
        if j == 2 && i == length(f), sl = true; else sl = false; end

        [HR(:,:,k),FAR(k),cHR(:,:,k),Sens(:,k)] = PsychGenPlot(schedule, ...
            'Parent',gca,'condition',cvar,'dependant',dvar, ...
            'xscale','linear','showlegend',sl);
        
        Subj(k) = str2num(strtok(f(i).name,'-'));
        
        fprintf('%s\n',f(i).name)
        
        title(gca,sprintf('Subj %d',Subj(k)));
        
        k = k + 1;
    end
end

ax = findobj(gcf,'type','axes');
set(ax,'xlim',[20 70]);


% summary of sensitivites: first column is 'Condition', first row is 'Subject'
t = [Subj; Sens];
t = sortrows(t')';
x = strfind(schedule.readparams,cvar);
i = findincell(x,1);
x = unique(schedule.response_vals(:,i+1));
sens_summary = [x, t] %#ok<NOPTS>


% store schedule with figure
set(gcf,'UserData',schedule);

%
dstr = sprintf('%s | %s',datestr(datevec(f(1).date),'ddd, mmm dd, yyyy'),strtok(schedule.schedule,'.'));
set(gcf,'name',dstr,'WindowStyle','docked','NumberTitle','off');

figure
bar(1:4,Sens)
set(gca,'xticklabel',x(2:end))
ylabel('Threshold (dB SPL)')
xlabel('HP (Hz)')
ylim([0 100])
set(gcf,'name',dstr,'WindowStyle','docked','NumberTitle','off');
